<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      body {
        margin: 0;
        padding: 0;
        background: url(../images/grid.png);
      }
      canvas {
        background-color: rgba(255, 0, 0, 0.1);
      }
    </style>
  </head>
  <body>
    <canvas id="tutorial" width="180" height="130">
      您的浏览器不兼容canvas，请升级浏览器
    </canvas>

    <script>
      window.onload = function () {
        let canvasEl = document.getElementById('tutorial')
        if (!canvasEl.getContext) {
          return
        }

        let ctx = canvasEl.getContext('2d') // 2d | webgl

        ctx.fillStyle = 'red'
        ctx.fillRect(10, 10, 30, 15)
        ctx.save()

        ctx.fillStyle = 'green'
        ctx.fillRect(50, 10, 30, 15)
        ctx.save()

        ctx.fillStyle = 'blue'
        ctx.fillRect(90, 10, 30, 15)
        ctx.save()

        // ctx.fillStyle = 'blue'
        ctx.restore()
        ctx.fillRect(90, 40, 30, 80)

        // ctx.fillStyle = 'green'
        ctx.restore()
        ctx.fillRect(50, 40, 30, 80)

        // ctx.fillStyle = 'red'
        ctx.restore()
        ctx.fillRect(10, 40, 30, 80)
      }
    </script>
  </body>
</html>
